package com.ragdollcat.thirdaicodegenerate.core.saver;

import com.ragdollcat.thirdaicodegenerate.enums.CodeGenTypeEnum;
import com.ragdollcat.thirdaicodegenerate.core.MultiFileCodeResult;

import java.io.File;

/**
 * 多文件保存
 */
public class MutliFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult> {

    @Override
    public String makeUniqueContents(Long appId, int version) {
        return CodeGenTypeEnum.MULTI_FILE.getValue() + "_" + appId + "_" + version;
    }

    @Override
    public void save(String path, MultiFileCodeResult codeParseResult) {
        if (codeParseResult.getHtmlCode() != null) {
            super.doSave(path + File.separator + "index.html", codeParseResult.getHtmlCode());
        }
        if (codeParseResult.getCssCode() != null) {
            super.doSave(path + File.separator + "style.css", codeParseResult.getCssCode());
        }
        if (codeParseResult.getJsCode() != null) {
            super.doSave(path + File.separator + "script.js", codeParseResult.getJsCode());
        }
    }
}
